//
//  FindViewController.m
//  Travel assistant
//
//  Created by 杨帆 on 16/2/27.
//  Copyright © 2016年 旅游助手. All rights reserved.
//

#import "FindViewController.h"
#import "FindGenerTableViewCell.h"
#import "FindClickTableViewCell.h"
@interface FindViewController ()

@property (nonatomic,assign)BOOL key;

@end

@implementation FindViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"发现";
    
    self.tableView.showsVerticalScrollIndicator = NO;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"FindGenerTableViewCell" bundle:nil] forCellReuseIdentifier:@"Cell"];
    
    if (self.key == YES) {
        self.tableView.frame = CGRectMake(0, 60, self.view.frame.size.height, self.view.frame.size.width);
    }else{
        self.tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.key == YES) {
        return self.tableView.frame.size.height;
    }else{
        return 200;
    }
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    if (self.key == YES) {
        
        FindClickTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CELL" forIndexPath:indexPath];
        
        return cell;
    }else{
        
        FindGenerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
        
        return cell;
    }
    
    
    
    return NO;
    
    // Configure the cell...
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    self.tableView.transform = CGAffineTransformMakeRotation(-M_PI/2);
    
    [self.tableView registerNib:[UINib nibWithNibName:@"FindClickTableViewCell" bundle:nil] forCellReuseIdentifier:@"CELL"];
    
    self.tableView.frame = CGRectMake(-60, 60, self.view.frame.size.width*2, self.view.frame.size.height);
    
    self.navigationItem.title = @"发现";
    
    self.tableView.pagingEnabled = YES;
    
    self.navigationItem.hidesBackButton = YES;
    
    self.tableView.showsVerticalScrollIndicator = NO; // 隐藏滚动条
    
    self.tabBarController.tabBar.hidden = YES;
    
    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]initWithTitle:@"列表" style:(UIBarButtonItemStylePlain) target:self action:@selector(RightbarbuttonAction)];
    
    self.navigationItem.rightBarButtonItem = rightBarButton;
    
    [self.tableView reloadData];
    
    self.key = YES;
    
}

- (void)RightbarbuttonAction{
    
    self.key = NO;
    
    self.navigationItem.rightBarButtonItem = nil;
    
    self.tableView.scrollEnabled = YES;
    
    self.tabBarController.tabBar.hidden = NO;
    
    CGAffineTransform transform = CGAffineTransformMakeRotation(0);
    
    self.tableView.transform = transform;
    
    [self.tableView reloadData];
    
    
}


-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (self.key == YES) {
    CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2);
    
    cell.contentView.transform = transform;
    }
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
